import { get, post, postBlob } from '@/utils/http'
import type { BasicPagingListResult, BasicPagingListParams } from '@/apis/basicModel'
import type { IReportParams, IReportResult, ICreateReport } from './model/reportModel'
enum Api {
  // 分页查询报告
  GET_REPORT_LIST = '/footprint/model/report/pageReport',
  CREATE_REPORT = '/footprint/model/report/createReport',
  DEL_REPORT = '/footprint/model/report/deleteReport',
  // 导出数据清单
  EXPORT_DATA = '/footprint/model/report/exportDataList',
  // 导出报告
  EXPORT_REPORT = '/footprint/model/report/exportReport',
  RAW_MATERIA = '/footprint/model/report/exportReportRawMaterialObtainProcess',
  LIFE_CYCLE = '/footprint/model/report/exportReportProductLifecycle'
}

// 分页查询报告
export const getFootprintReportList = (
  params: BasicPagingListParams & IReportParams
): Promise<BasicPagingListResult<IReportResult>> => get(Api.GET_REPORT_LIST, params)

// 创建报告
export const createReport = (modelNo: string): Promise<void> => post(Api.CREATE_REPORT, { modelNo })

// 删除报告
export const delReport = (reportNo: string): Promise<void> => post(Api.DEL_REPORT, { reportNo })

// 导出数据清单
export const exportDataList = (params: { reportNo: string }) => postBlob(Api.EXPORT_DATA, params)

export const exportDataReport = (params: ICreateReport) => postBlob(Api.EXPORT_REPORT, params)

export const loadRawMateria = (reportNo: string): Promise<INameValue[]> =>
  post(Api.RAW_MATERIA, { reportNo })

export const loadLifeCycle = (reportNo: string): Promise<INameValue[]> =>
  post(Api.LIFE_CYCLE, { reportNo })
